import datetime
import hashlib

__all__ = ['last7', 'last30', 'today', 'yesterday', 'this_month', 'last_month', 'get_md5']
now = datetime.datetime.now()
last_month_date = now.replace(day=1) - datetime.timedelta(days=1)

last7 = {
            "start_date": (now - datetime.timedelta(7)).strftime("%Y-%m-%d"),
            "end_date": now.strftime("%Y-%m-%d")
    }

last30 = {
            "start_date": (now - datetime.timedelta(30)).strftime("%Y-%m-%d"),
            "end_date": now.strftime("%Y-%m-%d")
    }
today = {
            "start_date": now.strftime("%Y-%m-%d"),
            "end_date": now.strftime("%Y-%m-%d")
    }

yesterday = {
            "start_date": (now - datetime.timedelta(1)).strftime("%Y-%m-%d"),
            "end_date": (now - datetime.timedelta(1)).strftime("%Y-%m-%d"),
    }

this_month = {
            "start_date": now.strftime("%Y-%m-01"),
            "end_date": now.strftime("%Y-%m-%d"),
    }

last_month = {
            "start_date": last_month_date.strftime("%Y-%m-01"),
            "end_date": last_month_date.strftime("%Y-%m-%d"),
    }


def get_md5(message):
    m = hashlib.md5()
    m.update(message.encode(encoding='utf-8'))
    return m.hexdigest()

